package admin

import (
	"html/template"
	"git.oschina.net/fuxiaohei/fuxiaohei-go.git/Core"
)

// Render admin page
// add header and footer automatically, add basic meta data
func RenderAdminPage(tplName string, data map[string]interface {}, fnMap template.FuncMap, rel string) string {
	tpl := []string{Core.ThemeFile("admin", tplName)}
	if data == nil {
		data = make(map[string]interface {})
	}
	data["Rel"] = rel
	data["SiteName"] = metaString("site_name")
	tpl = append(tpl, Core.ThemeFile("admin", "header.html"))
	return Core.RenderFiles(tpl, data, fnMap)
}

// get meta string from key string
func metaString(key string) string {
	sql := Core.Sql("fuxiaohei_metas", "value").Where("key = ?").Select()
	data := Core.Db.One(sql, key)
	if len(data) < 1 {
		return ""
	}
	return data["value"]
}

